/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ucm;

/**
 *
 * @author Stan
 */
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


import java.sql.Connection;
import java.sql.DriverManager;

public class DBConnect {

    private  Connection connection;
    private static String hostName = "localhost:3306";
    private static String databaseName = "airport";
    private static String databaseUsername = "root";
    private static String databasePassword = "zhujian";

    public boolean CreateConnect() {
        if (null == connection) {
            try {
                Class.forName("com.mysql.jdbc.Driver");
                connection = DriverManager.getConnection(
                        "jdbc:mysql://" + hostName + "/" + databaseName, databaseUsername, databasePassword);
                return true;

            } catch (Exception e) {
                System.out.println(e);
                e.printStackTrace();
                return false;
            }
        }
        return false;
    }

    public Connection getConnection() {
        if (null == connection) {
            CreateConnect();
        }
        return connection;

    }
}
